package fr.uniscol.siecle.dao.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import fr.uniscol.siecle.model.Eleve;
import fr.uniscol.siecle.model.Matiere;
import fr.uniscol.siecle.model.ModaliteElection;
import fr.uniscol.siecle.model.Option;
import fr.uniscol.siecle.model.OptionEleve;

public class OptionEleveRowMapper implements RowMapper<OptionEleve> {
	
	@Override
	public OptionEleve mapRow(ResultSet rs, int rowNum) throws SQLException {
		
		OptionEleve opt = new OptionEleve();
		
		Eleve eleve = new Eleve();
		eleve.setId(rs.getString("ELEVE_ID"));
		opt.setEleve(eleve);
		
		Matiere matiere = new Matiere();
		matiere.setCode(rs.getString("CODE_MATIERE"));
		
		ModaliteElection modalite = new ModaliteElection();
		modalite.setCode(rs.getString("CODE_MODALITE"));
		
		Option option = new Option();
		option.setEleve(eleve);
		option.setMatiere(matiere);
		option.setModalite(modalite);
		option.setNum_option(rs.getString("NUM_OPTION"));
		
		opt.getOptions().add(option);
		
		return opt;
	}
}
